import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {NzSafeAny} from 'ng-zorro-antd/core/types';
import {NzUploadChangeParam} from 'ng-zorro-antd/upload';
import {NzMessageService} from 'ng-zorro-antd/message';

interface ActionCodeObj {
  add?: string;
}

@Component({
  selector: 'app-card-table-wrap',
  templateUrl: './card-table-wrap.component.html',
  styleUrls: ['./card-table-wrap.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class CardTableWrapComponent implements OnInit {
  @Input() needAddBtn: boolean;
  @Input() needDelBtn: boolean;
  @Input() needImpBtn: boolean;
  // @Input() needExpBtn: boolean;
  @Output() add = new EventEmitter<NzSafeAny>();
  @Output() del = new EventEmitter<NzSafeAny>();
  // @Output() import = new EventEmitter<NzSafeAny>();
  // @Output() export = new EventEmitter<NzSafeAny>();
  @Input() actionCode!: ActionCodeObj;
  uploadUrl: string;

  constructor(private msg: NzMessageService) {
    this.uploadUrl = '/site/import-question';
    this.needAddBtn = false;
    this.needDelBtn = false;
    //  this.needExpBtn = false;
    this.needImpBtn = false;
  }

  addBtnClick(): void {
    this.add.emit();
  }

  delBtnClick(): void {
    this.del.emit();
  }

  impBtnClick(info: NzUploadChangeParam): void {
    if (info.file.status !== 'uploading') {
      console.log(info.file, info.fileList);
    }
    if (info.file.status === 'done') {
      this.msg.success(`${info.file.name} file uploaded successfully`);
    } else if (info.file.status === 'error') {
      this.msg.error(`${info.file.name} file upload failed.`);
    }

  }

  /*expBtnClick(): void {
    this.export.emit();
  }*/

  ngOnInit(): void {
  }

}
